home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-02-27 | 4.8 KB | 148 lines | [TEXT/PJMM] |
- { StubCDEFIntf }
- {}
- { Interface to the StubCDEF control }
- {}
- { Copyright © Sebastiano Pilla 1996 }
- { All rights reserved }
-
- { <mailto:case@tvol.it> }
-
- { This unit handles the creation and initialization of a control with the stub method }
-
- unit StubCDEFIntf;
-
-
- interface
-
-
- { InstallRealCDEFUPP }
- {}
- { Loads a control template and installs the real control definition procedure into the refCon; also initializes }
- { the control by calling explicitly the given defproc with the initCntl message }
- {}
- { Entry: inControlDefProcPtr = pointer to the real control definition }
- { inWindPtr = pointer to the window to which the control belongs }
- { inCtrlTemplateID = res. ID of a CNTL resource, whose procID field is defined as }
- { (16 * StubCDEF resource ID) + variation code }
- { Exit: outControlHdl = handle to newly created control (or NIL if errors) }
- { function result = result given by the real defproc to the initCntl message }
- function InstallRealCDEFUPP (var outControlHdl: ControlHandle;
- inControlDefProcPtr: ControlDefProcPtr;
- inWindPtr: WindowPtr;
- inCtrlTemplateID: SInt16): SInt32;
-
-
- { AttachRealCDEFUPP }
- {}
- { Attaches the given control definition procedure to an already created control, and calls the defproc }
- { explicitly with the initCntl message }
- {}
- { Entry: inControlDefProcPtr = pointer to the real control definition }
- { inControlHdl = handle to a control }
- { Exit: function result = result given by the real defproc to the initCntl message }
- function AttachRealCDEFUPP (inControlDefProcPtr: ControlDefProcPtr;
- inControlHdl: ControlHandle): SInt32;
-
-
- { RemoveRealCDEFUPP }
- {}
- { Calls the control's defproc with the dispCntl message and removes the defproc from the given control's refCon }
- {}
- { Entry: inControlHdl = handle to control }
- { Exit: function result = result given by the real defproc to the dispCntl message }
- function RemoveRealCDEFUPP (inControlHdl: ControlHandle): SInt32;
-
-
- implementation
-
-
- const
- kCNTLResType = 'CNTL';
-
-
- function InstallRealCDEFUPP (var outControlHdl: ControlHandle;
- inControlDefProcPtr: ControlDefProcPtr;
- inWindPtr: WindowPtr;
- inCtrlTemplateID: SInt16): SInt32;
- var
- ctrlDefUPP: ControlDefUPP;
- result: SInt32;
- begin
- outControlHdl := nil;
- result := 0;
-
- { Get the control from the resource file and install it into the given window's controls list }
- outControlHdl := GetNewControl(inCtrlTemplateID, inWindPtr);
-
- if outControlHdl <> nil then
- begin
-
- { Create the control definition UPP }
- ctrlDefUPP := NewControlDefProc(inControlDefProcPtr);
-
- { Store the control definition UPP into the control's refCon }
- SetControlReference(outControlHdl, SInt32(ctrlDefUPP));
-
- { Call explicitly the control defProc with the initCntl message; this is necessary to have the control's }
- { defProc properly do its initialization, because this message has been sent at the time of the GetNewControl }
- { call to the stub, which obviously cannot know anything about our particular control }
- result := CallControlDefProc(GetControlVariant(outControlHdl), outControlHdl, initCntl, 0, ctrlDefUPP);
- end;
-
- InstallRealCDEFUPP := result;
- end;
-
-
- function AttachRealCDEFUPP (inControlDefProcPtr: ControlDefProcPtr;
- inControlHdl: ControlHandle): SInt32;
- var
- ctrlDefUPP: ControlDefUPP;
- result: SInt32;
- begin
- result := 0;
-
- if inControlHdl <> nil then
- begin
-
- { Create the control definition UPP }
- ctrlDefUPP := NewControlDefProc(inControlDefProcPtr);
-
- { Store the control definition UPP into the control's refCon }
- SetControlReference(inControlHdl, SInt32(ctrlDefUPP));
-
- { Call explicitly the control defProc with the initCntl message; this is necessary to have the control's }
- { defProc properly do its initialization, because this message has been sent at the time of the GetNewControl }
- { call to the stub, which obviously cannot know anything about our particular control }
- result := CallControlDefProc(GetControlVariant(inControlHdl), inControlHdl, initCntl, 0, ctrlDefUPP);
- end;
-
- AttachRealCDEFUPP := result;
- end;
-
-
- function RemoveRealCDEFUPP (inControlHdl: ControlHandle): SInt32;
- var
- ctrlDefUPP: ControlDefUPP;
- result: SInt32;
- begin
- result := 0;
-
- if inControlHdl <> nil then
- begin
- ctrlDefUPP := ControlDefUPP(GetControlReference(inControlHdl));
-
- if ctrlDefUPP <> nil then
- begin
-
- { Call explicitly the control defProc with the dispCntl message; this is necessary to the real defProc to properly }
- { deallocate any private storage, ecc. This message cannot be understood by the stub procedure, which obviously }
- { cannot know anything about our control }
- result := CallControlDefProc(GetControlVariant(inControlHdl), inControlHdl, dispCntl, 0, ctrlDefUPP);
- DisposeRoutineDescriptor(ctrlDefUPP);
- end;
- end;
- RemoveRealCDEFUPP := result;
- end;
-
-
- end.